home *** CD-ROM | disk | FTP | other *** search
- Path: li.net!jeremy
- From: jeremy@newshost.li.net (Jeremy Markman)
- Newsgroups: comp.lang.c
- Subject: Re: Help! Can't read input from keyboard!
- Date: 2 Apr 1996 14:39:10 GMT
- Organization: LI Net (Long Island Network)
- Message-ID: <4jre6e$op1@linet06.li.net>
- References: <4jq0ts$5mh@taniemarie.solon.com>
- NNTP-Posting-Host: linet04.li.net
- X-Newsreader: TIN [version 1.2 PL2]
-
- Peter Seebach (seebs@taniemarie.solon.com) wrote:
- : I guess I thought I knew C, but maybe not. The following program compiles
-
- Maybe Not...
-
- First, the sscanf() function will read in input from a string. You did
- not specify a string, which is why you got an error originally when
- compiling.
- Second, using scanf(), even when used correctly, is not recommended for
- reading in user input. Use the getch() function to read in one character
- at a time from the keyboard, then parse the characters you read in to
- make sure you are getting the input you are looking for.
- Here's a quick example:
-
- int main()
- {
- int ch;
-
- ch = getch();
- printf("%c\n",ch);
-
- return(0);
- }
-
-
- Old Code:
- : int main(void) {
- : int i = 0;
- : (void) sscanf, "3", "%d", i;
- : (void) printf, "%d", i;
- : return 0;
- : }
-